package com.hs.controller;

import com.hs.config.R;
import com.hs.entity.IssueFlush;
import com.hs.service.IssueFlushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("issueFlush")
@Controller
public class IssueFlushController {

    @Autowired
    IssueFlushService issueFlushService;

    @RequestMapping("insert")
    @ResponseBody
    public R insert(IssueFlush record, Model model) {
        if (record == null) {
            return R.FAILURE("请填写关键信息", null);
        }
        if (record.getIssueId() == null) {
            model.addAttribute("msg", "请填写期数关键值");
            return R.FAILURE("请填写期数关键值", null);
        }
        int i = issueFlushService.insertSelective(record);
        if (i > 0) {
            return R.SUCCESS("", i);
        }
        return R.FAILURE("", 0);
    }

    @RequestMapping("issueFlush")
    @ResponseBody
    public R IssueFlush(IssueFlush record, Model model, HttpSession session) {
        if (record == null) {
            return R.FAILURE("请填写关键信息", null);
        }
        if (record.getIssueId() == null) {
            model.addAttribute("msg", "请填写期数关键值");
            return R.FAILURE("请填写期数关键值", null);
        }
        List<IssueFlush> issueFlushes = issueFlushService.selectByCondition(record);
        if (issueFlushes!=null && issueFlushes.size() > 0) {
            return R.SUCCESS("", issueFlushes);
        }

        return R.FAILURE("还没有参与数据！", null);
    }




}
